<?php


function menuList($data, $parent,$brand_id)
{
		static $i = 1;
		$tab = str_repeat(" ",$i);
		if(isset($data[$parent]))
		{
		$html = "$tab";
		$i++;
		foreach($data[$parent] as $key => $v)
		{
			
			$child = menuList($data, $v->kategori_id,$brand_id);
			//echo $key;
			//if (in_array($v->kategori_id,$urai)){
				if($key != 0)
				{
					$html .= "$tab<br>";
					if($v->kat_level == 1){
						
							$html .= '<strong style="color:#ccc;text-decoration:underline;">'.$v->nama_kategori.'</strong>';
							$html .= "$tab<br>";
					}
					elseif($v->kat_level == 2){
						$html .= '<strong>'.$v->nama_kategori.'</strong>';
						$html .= "$tab<br>";
					}
					elseif($v->kat_level == 3){
						$html .= '<a href="'.base_url().'produk/kategori/'.$brand_id.'/'.$v->kategori_id.'/'.alias($v->nama_kategori).'">'.$v->nama_kategori.'</a>';
					
					}
					
					if($child)
					{
					$i--;
					$html .= $child;
					$html .= "$tab";
					}
				}
				else
				{
					if($v->kat_level == 1){
						
						$html .= '<strong style="color:#ccc;text-decoration:underline;">'.$v->nama_kategori.'</strong>';
							$html .= "$tab<br>";
					}
					elseif($v->kat_level == 2){
						$html .= '<strong>'.$v->nama_kategori.'</strong>';
						$html .= "$tab<br>";
					
					}
					elseif($v->kat_level == 3){
						$html .= '<a href="'.base_url().'produk/kategori/'.$brand_id.'/'.$v->kategori_id.'/'.alias($v->nama_kategori).'">'.$v->nama_kategori.'</a>';
					
					}
					
					if($child)
					{
					$i--;
					$html .= $child;
				
					}
				}
		//	}
			//$html .= '</li>';
		}
		//$html .= "$tab";
		return $html;
		}
		else
		{
		return false;
		}
}

// TAMPIL CAPTION SEBELAH KIRI				
function getBrandKategori($brand_id,$pos)
{
		$query = mysql_query("
		SELECT * FROM tb_kat_produk kat
		WHERE brand_id = $brand_id AND caps_posisi = '$pos'
		GROUP BY kategori_id ORDER BY kat.urut 
		");

		$num_rows = mysql_num_rows($query);
		
		if ($num_rows > 0):
			while($r=mysql_fetch_object($query))
			{
			$data[$r->parent_kat_id][] = $r;
			}
			$menu = menuList($data,0,$brand_id);
			return $menu;
		else:
			$menu = 'Not Available';
			return $menu;
		endif;
		
	}
	
// TAMPIL CAPTION SEBELAH KANAN
function getBrandKategori2($brand_id,$pos)
{
		$query = mysql_query("
		SELECT * FROM tb_kat_produk kat
		WHERE brand_id = $brand_id AND caps_posisi = '$pos'
		GROUP BY kategori_id ORDER BY kat.urut 
		");

		$num_rows = mysql_num_rows($query);
		
		if ($num_rows > 0):
			while($r=mysql_fetch_object($query))
			{
			$data[$r->parent_kat_id][] = $r;
			}
			$menu = menuList($data,0,$brand_id);
			return $menu;
		else:
			$menu = 'Not Available';
			return $menu;
		endif;
		
	}
	
	


?>